package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * JDBC执行DML语句:UPDATE
 * 修改密码
 * 结果: 修改成功 | 该用户不存在,修改失败
 */
public class JDBCDemo02 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class cls = Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root", "root");
        Statement statement = conn.createStatement();
        System.out.println("请输入新密码: ");
        Scanner sc = new Scanner(System.in);
        String password = sc.next();
        String sql = "Update userinfo set password = '"+password+"' where username = 'Tony'";
        int i = statement.executeUpdate(sql);
        if (i > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("该用户不存在,修改失败");
        }
        conn.close();
    }



}
